package test;

import java.util.Arrays;
import java.util.Scanner;

interface IntegerStack{
	public Integer push(Integer item);//如果item为null，则不入栈直接返回null。如果栈满，也返回null。如果插入成功，返回item。
	public Integer pop(); //出栈，如果为空，则返回null。出栈时只移动栈顶指针，相应位置不置为null
	public Integer peek(); //获得栈顶元素，如果为空，则返回null.
	public boolean empty(); //如果为空返回true
	public int size(); //返回栈中元素个数
}

public class M {

		private static Scanner in;

		public static void main(String[] args) {
			in = new Scanner(System.in);
			int n = in.nextInt();
			ArrayIntegerStack Stack = new ArrayIntegerStack(n);
			int m = in.nextInt();
			for (int i = 0; i < m; i++) {
				Integer number = in.nextInt();
				System.out.println(Stack.push(number));
			}
			System.out.print(Stack.peek() + "," + Stack.empty() + "," + Stack.size() + "\n");
			System.out.println(Arrays.toString(Stack.getStack()));
			int x = in.nextInt();
			for (int i = 0; i < x; i++) {
				System.out.println(Stack.pop());
			}
			System.out.print(Stack.peek() + "," + Stack.empty() + "," + Stack.size() + "\n");
			System.out.println(Arrays.toString(Stack.getStack()));
		}
}
class ArrayIntegerStack implements IntegerStack {

	private Integer[] arr;
	private int top;

	public ArrayIntegerStack(int n) {
		this.arr = new Integer[n];
	}
    public Integer push(Integer item) {
		if (item == null)	
		return null;
		if(this.size() >= this.arr.length )	
		return null;
		arr[top] = item;
		top++;
		return item;          
	}

	public Integer pop() {
		if(this.empty())
		return null;
		top--;
		return arr[top];
	}

	public Integer peek() {
		if(this.empty())	
		return null;
		return arr[top - 1];
	}

	public boolean empty() {
		if(top == 0)	
		return true;
		return false;
	}

	public int size() {
		return top;
	}

	public Integer[] getStack() {
		return arr;
	}
}
	 

